{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.metrics import r2_score\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>weekday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>...</th>\n",
       "      <th>dteday_2012-12-24</th>\n",
       "      <th>dteday_2012-12-25</th>\n",
       "      <th>dteday_2012-12-26</th>\n",
       "      <th>dteday_2012-12-27</th>\n",
       "      <th>dteday_2012-12-28</th>\n",
       "      <th>dteday_2012-12-29</th>\n",
       "      <th>dteday_2012-12-30</th>\n",
       "      <th>dteday_2012-12-31</th>\n",
       "      <th>cnt</th>\n",
       "      <th>log_cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-1.729683</td>\n",
       "      <td>-1.348213</td>\n",
       "      <td>-1.001369</td>\n",
       "      <td>-1.600161</td>\n",
       "      <td>1.498809</td>\n",
       "      <td>1.110427</td>\n",
       "      <td>-0.826662</td>\n",
       "      <td>-0.679946</td>\n",
       "      <td>1.250171</td>\n",
       "      <td>-0.387892</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.817953</td>\n",
       "      <td>-2.387564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-1.724944</td>\n",
       "      <td>-1.348213</td>\n",
       "      <td>-1.001369</td>\n",
       "      <td>-1.600161</td>\n",
       "      <td>-1.496077</td>\n",
       "      <td>1.110427</td>\n",
       "      <td>-0.721095</td>\n",
       "      <td>-0.740652</td>\n",
       "      <td>0.479113</td>\n",
       "      <td>0.749602</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.912999</td>\n",
       "      <td>-2.742332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-1.720205</td>\n",
       "      <td>-1.348213</td>\n",
       "      <td>-1.001369</td>\n",
       "      <td>-1.600161</td>\n",
       "      <td>-0.996930</td>\n",
       "      <td>-0.726048</td>\n",
       "      <td>-1.634657</td>\n",
       "      <td>-1.749767</td>\n",
       "      <td>-1.339274</td>\n",
       "      <td>0.746632</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.629925</td>\n",
       "      <td>-1.847887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-1.715466</td>\n",
       "      <td>-1.348213</td>\n",
       "      <td>-1.001369</td>\n",
       "      <td>-1.600161</td>\n",
       "      <td>-0.497782</td>\n",
       "      <td>-0.726048</td>\n",
       "      <td>-1.614780</td>\n",
       "      <td>-1.610270</td>\n",
       "      <td>-0.263182</td>\n",
       "      <td>-0.389829</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.519898</td>\n",
       "      <td>-1.596254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.710728</td>\n",
       "      <td>-1.348213</td>\n",
       "      <td>-1.001369</td>\n",
       "      <td>-1.600161</td>\n",
       "      <td>0.001366</td>\n",
       "      <td>-0.726048</td>\n",
       "      <td>-1.467414</td>\n",
       "      <td>-1.504971</td>\n",
       "      <td>-1.341494</td>\n",
       "      <td>-0.046307</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.500269</td>\n",
       "      <td>-1.554995</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 749 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    instant    season        yr      mnth   weekday  weathersit      temp  \\\n",
       "0 -1.729683 -1.348213 -1.001369 -1.600161  1.498809    1.110427 -0.826662   \n",
       "1 -1.724944 -1.348213 -1.001369 -1.600161 -1.496077    1.110427 -0.721095   \n",
       "2 -1.720205 -1.348213 -1.001369 -1.600161 -0.996930   -0.726048 -1.634657   \n",
       "3 -1.715466 -1.348213 -1.001369 -1.600161 -0.497782   -0.726048 -1.614780   \n",
       "4 -1.710728 -1.348213 -1.001369 -1.600161  0.001366   -0.726048 -1.467414   \n",
       "\n",
       "      atemp       hum  windspeed    ...     dteday_2012-12-24  \\\n",
       "0 -0.679946  1.250171  -0.387892    ...                     0   \n",
       "1 -0.740652  0.479113   0.749602    ...                     0   \n",
       "2 -1.749767 -1.339274   0.746632    ...                     0   \n",
       "3 -1.610270 -0.263182  -0.389829    ...                     0   \n",
       "4 -1.504971 -1.341494  -0.046307    ...                     0   \n",
       "\n",
       "   dteday_2012-12-25  dteday_2012-12-26  dteday_2012-12-27  dteday_2012-12-28  \\\n",
       "0                  0                  0                  0                  0   \n",
       "1                  0                  0                  0                  0   \n",
       "2                  0                  0                  0                  0   \n",
       "3                  0                  0                  0                  0   \n",
       "4                  0                  0                  0                  0   \n",
       "\n",
       "   dteday_2012-12-29  dteday_2012-12-30  dteday_2012-12-31       cnt   log_cnt  \n",
       "0                  0                  0                  0 -1.817953 -2.387564  \n",
       "1                  0                  0                  0 -1.912999 -2.742332  \n",
       "2                  0                  0                  0 -1.629925 -1.847887  \n",
       "3                  0                  0                  0 -1.519898 -1.596254  \n",
       "4                  0                  0                  0 -1.500269 -1.554995  \n",
       "\n",
       "[5 rows x 749 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=pd.read_csv('FE_sharingbike.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#分离xy\n",
    "y=df['cnt']\n",
    "x=df.drop(['cnt','log_cnt'],axis=1)\n",
    "feat_names=x.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(584, 747)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#建立训练集和测试集\n",
    "from sklearn.model_selection import train_test_split\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=33,test_size=0.2)#使用20%做为测试集\n",
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.796683</td>\n",
       "      <td>registered</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.426234</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.353279</td>\n",
       "      <td>casual</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.239660</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>531</th>\n",
       "      <td>0.040750</td>\n",
       "      <td>dteday_2012-05-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>685</th>\n",
       "      <td>0.040522</td>\n",
       "      <td>dteday_2012-10-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>0.040058</td>\n",
       "      <td>dteday_2011-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>653</th>\n",
       "      <td>0.039851</td>\n",
       "      <td>dteday_2012-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>0.039739</td>\n",
       "      <td>dteday_2011-04-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>471</th>\n",
       "      <td>0.039261</td>\n",
       "      <td>dteday_2012-03-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>532</th>\n",
       "      <td>0.038797</td>\n",
       "      <td>dteday_2012-05-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>470</th>\n",
       "      <td>0.038432</td>\n",
       "      <td>dteday_2012-03-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>378</th>\n",
       "      <td>0.037494</td>\n",
       "      <td>dteday_2011-12-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>654</th>\n",
       "      <td>0.036306</td>\n",
       "      <td>dteday_2012-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>411</th>\n",
       "      <td>0.035830</td>\n",
       "      <td>dteday_2012-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>0.035792</td>\n",
       "      <td>dteday_2011-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>0.035695</td>\n",
       "      <td>dteday_2012-11-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>681</th>\n",
       "      <td>0.035290</td>\n",
       "      <td>dteday_2012-10-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>622</th>\n",
       "      <td>0.035251</td>\n",
       "      <td>dteday_2012-08-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>743</th>\n",
       "      <td>0.035156</td>\n",
       "      <td>dteday_2012-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>0.034174</td>\n",
       "      <td>dteday_2012-04-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>0.034109</td>\n",
       "      <td>dteday_2011-06-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>0.033641</td>\n",
       "      <td>dteday_2012-04-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>624</th>\n",
       "      <td>0.033539</td>\n",
       "      <td>dteday_2012-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>714</th>\n",
       "      <td>0.033422</td>\n",
       "      <td>dteday_2012-11-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>377</th>\n",
       "      <td>0.032770</td>\n",
       "      <td>dteday_2011-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>409</th>\n",
       "      <td>0.032565</td>\n",
       "      <td>dteday_2012-01-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>593</th>\n",
       "      <td>0.032377</td>\n",
       "      <td>dteday_2012-07-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>410</th>\n",
       "      <td>0.032193</td>\n",
       "      <td>dteday_2012-01-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>0.031990</td>\n",
       "      <td>dteday_2012-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>-0.031634</td>\n",
       "      <td>dteday_2012-04-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>656</th>\n",
       "      <td>-0.031667</td>\n",
       "      <td>dteday_2012-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>-0.031958</td>\n",
       "      <td>dteday_2012-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>-0.032124</td>\n",
       "      <td>dteday_2012-07-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>626</th>\n",
       "      <td>-0.032453</td>\n",
       "      <td>dteday_2012-09-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>-0.032666</td>\n",
       "      <td>dteday_2011-09-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>594</th>\n",
       "      <td>-0.032676</td>\n",
       "      <td>dteday_2012-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>-0.032744</td>\n",
       "      <td>dteday_2011-12-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>-0.032921</td>\n",
       "      <td>dteday_2012-07-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>627</th>\n",
       "      <td>-0.032992</td>\n",
       "      <td>dteday_2012-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>-0.033133</td>\n",
       "      <td>dteday_2011-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>-0.033140</td>\n",
       "      <td>dteday_2012-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>412</th>\n",
       "      <td>-0.033243</td>\n",
       "      <td>dteday_2012-02-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>-0.033266</td>\n",
       "      <td>dteday_2011-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>598</th>\n",
       "      <td>-0.033463</td>\n",
       "      <td>dteday_2012-08-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>442</th>\n",
       "      <td>-0.033916</td>\n",
       "      <td>dteday_2012-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>-0.034170</td>\n",
       "      <td>dteday_2011-04-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>229</th>\n",
       "      <td>-0.034439</td>\n",
       "      <td>dteday_2011-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.034496</td>\n",
       "      <td>dteday_2011-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>503</th>\n",
       "      <td>-0.035486</td>\n",
       "      <td>dteday_2012-05-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>-0.036167</td>\n",
       "      <td>dteday_2011-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>-0.036189</td>\n",
       "      <td>dteday_2011-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>-0.036384</td>\n",
       "      <td>dteday_2011-10-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>441</th>\n",
       "      <td>-0.036603</td>\n",
       "      <td>dteday_2012-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>-0.036933</td>\n",
       "      <td>dteday_2012-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>383</th>\n",
       "      <td>-0.038332</td>\n",
       "      <td>dteday_2012-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>-0.038944</td>\n",
       "      <td>dteday_2011-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>228</th>\n",
       "      <td>-0.039865</td>\n",
       "      <td>dteday_2011-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>381</th>\n",
       "      <td>-0.045532</td>\n",
       "      <td>dteday_2012-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.486398</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>747 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         coef            columns\n",
       "11   0.796683         registered\n",
       "2    0.426234                 yr\n",
       "10   0.353279             casual\n",
       "3    0.239660               mnth\n",
       "531  0.040750  dteday_2012-05-30\n",
       "685  0.040522  dteday_2012-10-31\n",
       "46   0.040058  dteday_2011-01-31\n",
       "653  0.039851  dteday_2012-09-29\n",
       "135  0.039739  dteday_2011-04-30\n",
       "471  0.039261  dteday_2012-03-31\n",
       "532  0.038797  dteday_2012-05-31\n",
       "470  0.038432  dteday_2012-03-30\n",
       "378  0.037494  dteday_2011-12-29\n",
       "654  0.036306  dteday_2012-09-30\n",
       "411  0.035830  dteday_2012-01-31\n",
       "258  0.035792  dteday_2011-08-31\n",
       "715  0.035695  dteday_2012-11-30\n",
       "681  0.035290  dteday_2012-10-27\n",
       "622  0.035251  dteday_2012-08-29\n",
       "743  0.035156  dteday_2012-12-28\n",
       "499  0.034174  dteday_2012-04-28\n",
       "196  0.034109  dteday_2011-06-30\n",
       "500  0.033641  dteday_2012-04-29\n",
       "624  0.033539  dteday_2012-08-31\n",
       "714  0.033422  dteday_2012-11-29\n",
       "377  0.032770  dteday_2011-12-28\n",
       "409  0.032565  dteday_2012-01-29\n",
       "593  0.032377  dteday_2012-07-31\n",
       "410  0.032193  dteday_2012-01-30\n",
       "439  0.031990  dteday_2012-02-28\n",
       "..        ...                ...\n",
       "473 -0.031634  dteday_2012-04-02\n",
       "656 -0.031667  dteday_2012-10-02\n",
       "595 -0.031958  dteday_2012-08-02\n",
       "569 -0.032124  dteday_2012-07-07\n",
       "626 -0.032453  dteday_2012-09-02\n",
       "259 -0.032666  dteday_2011-09-01\n",
       "594 -0.032676  dteday_2012-08-01\n",
       "350 -0.032744  dteday_2011-12-01\n",
       "567 -0.032921  dteday_2012-07-05\n",
       "627 -0.032992  dteday_2012-09-03\n",
       "261 -0.033133  dteday_2011-09-03\n",
       "565 -0.033140  dteday_2012-07-03\n",
       "412 -0.033243  dteday_2012-02-01\n",
       "198 -0.033266  dteday_2011-07-02\n",
       "598 -0.033463  dteday_2012-08-05\n",
       "442 -0.033916  dteday_2012-03-02\n",
       "109 -0.034170  dteday_2011-04-04\n",
       "229 -0.034439  dteday_2011-08-02\n",
       "16  -0.034496  dteday_2011-01-01\n",
       "503 -0.035486  dteday_2012-05-02\n",
       "76  -0.036167  dteday_2011-03-02\n",
       "106 -0.036189  dteday_2011-04-01\n",
       "289 -0.036384  dteday_2011-10-01\n",
       "441 -0.036603  dteday_2012-03-01\n",
       "564 -0.036933  dteday_2012-07-02\n",
       "383 -0.038332  dteday_2012-01-03\n",
       "75  -0.038944  dteday_2011-03-01\n",
       "228 -0.039865  dteday_2011-08-01\n",
       "381 -0.045532  dteday_2012-01-01\n",
       "0   -0.486398            instant\n",
       "\n",
       "[747 rows x 2 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr=LinearRegression()#建立线性回归模型\n",
    "lr.fit(x_train,y_train)#用训练集训练线性模型\n",
    "#对测试集进行预测\n",
    "y_test_pred_lr=lr.predict(x_test)\n",
    "y_train_pred_lr=lr.predict(x_train)\n",
    "#观察权重系数\n",
    "fs=pd.DataFrame({'columns':list(feat_names),'coef':list((lr.coef_.T))})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 score of LinearRegression on test is 0.9995392873788316\n",
      "the r2 score of LinearRegression on train is 1.0\n"
     ]
    }
   ],
   "source": [
    "#使用r2_score评价模型\n",
    "print('the r2 score of LinearRegression on test is',r2_score(y_test,y_test_pred_lr))\n",
    "print('the r2 score of LinearRegression on train is',r2_score(y_train,y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAF5CAYAAAC7qNLUAAAABHNCSVQICAgIfAhki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W+B1p933f+iuW+ldktjejJ6kvVKPXp6lNZbcXUJK0iSNpqY9FxHuqqdsdqZ3R69fAYwNblaRtgSEt9b0Z1A7YegLYl9q0qlNYkjrldLckSYVyJC1JUqH69WT+u+66a44fP74/n1KSpKIsWrToqcwcVc+2/RrS48ePZ+HChf35lJIkFSUi6j6LntPdkiQVypCWJKlQhrQkSYXq133SkqT2rVu3jhUrVvDSS56ZdHsxdOhQxo0bR1NTU7fbMKQlqQArVqzg9a9/PePHjyeity56poGSmaxZs4YVK1YwYcKEbrfjdLckFeCll15il112MaC3ExHBLrvs0uOZEUNakgphQG9feuP9NKQlSSqU+6QlqUAtLf3f3qBBgzj00ENZv349EyZM4Dvf+Q4jRozo8nOde+65fOxjH+Oggw561fprr72WhQsX8vWvf73LbQIMGzaMtWvX1rXt1KlTufzyy2lubt60buHChVx//fVcccUV3Xr+geBIWpIEwGtf+1oWL17MAw88wMiRI7nyyiu71c7VV1+9RUCXoLm5uc8DesOGDb3aniEtSdrClClTWLly5ablyy67jCOOOILDDjuMSy65BIDnn3+e6dOnM3HiRA455BDmzJkD1EaxG08B/e1vf5v99tuP448/nnvuuWdTe2effTZz587dtDxs2DAA1q5dy7Rp0zj88MM59NBDufXWW7eobdWqVRx33HFMmjSJQw45hLvuuquu1zR//nxOPPFEAFpaWjjnnHOYOnUqe+2116vC+4YbbuDII49k0qRJfPCDH9wUvBdccAHNzc0cfPDBm/oAaqe8vvTSS3nzm9/MLbfcUlct9XK6W5L0Khs2bGDevHnMmjULgDvuuIOlS5fyi1/8gszkpJNOYsGCBbS2trLHHntw++23A/DMM8+8qp1Vq1ZxySWXsGjRIoYPH85b3vIWJk+evNXnHjp0KD/4wQ/YaaedeOqppzj66KM56aSTXnUQ1ne/+11OOOEEPvvZz7JhwwZeeOGFbr3Ohx9+mDvvvJPnnnuO/fffnwsuuIBly5YxZ84c7rnnHpqamvjQhz7EjTfeyFlnncUXvvAFRo4cyYYNG5g2bRr3338/hx122Ka677777m7VsTWGtCQ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P36WphkiQ1rOpqVY9GxMZrEERETOxhm7dn5u6ZOT4zxwMvdDWgwZCWJDWY6sIYPwP2j4gV1YWCTgdmRcSvgAeBGV1o7y7gFmBa1V6H0+BdrtULbEiSVCZH0pIkFcqQliSpUIa0JEmFMqQlSSqUIS1JUqEMaUmSCmVIS5JUqP8PbGfyujGLa5MAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22e12736160>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#训练集上观察残差分布，是否是噪声为0的均值高斯噪声\n",
    "f,ax=plt.subplots(figsize=(7,5))\n",
    "f.tight_layout()\n",
    "ax.hist(y_train-y_train_pred_lr,bins=40,label='Residuals Linear',color='b',alpha=.5);\n",
    "ax.set_title('Historgram of Residuals')\n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xl8lPW1+PHPyWTfAwkgi4BAUUQQAQVXXCi4oEJR9KKvWistba22LhXFW/V6vS5YXO/Pili3aotW5QooiFjrVnYwiIgCKgIKhAAhIctkcn5/zASHmSEZYJ55JpPzfr3yYiaZ5/meF8vh+3yX8xVVxRhjnJDidgDGmORlCcYY4xhLMMYYx1iCMcY4xhKMMcYxlmCMMY6xBGOMcYwlGGOMYyzBGGMck+p2AAejuLhYu3Xr5nYYxrR6y5YtK1PVkuY+16ISTLdu3Vi6dKnbYRjT6onIN9F8zh6RjDGOsQRjjHGMawlGRDJFZLGIfCIiq0XkLrdiMcY4w80xmFrgLFWtFJE04EMReUt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ikA5cBb7gck6vEfwLg08AaVZ3qYhwljbObIpIFnEOM/r0k7UpeEXkV/4zJvrKcqrrZhTjWARnAjsC3FqqqKyVCRWQ08BhQAuwCVqrqiDi2fx7wMP4Zpb+o6j3xajskjr8Bw/CXJtgK3KGqT7sQx6nAB8Aq/H9PAW5T1TfjHEc/4Dn8fy4pwMuq+l8xuXeyJhhjjPuS9hHJGOM+SzDGGMdYgjHGOMYSjDHGMZZgjDGOadEL7UxsiUhbYEHgbQfAB2wPvD8xsIco3jHNA8YG9uqYFsamqU1EInInUKmqD4Z8X/D/vWmIeGHs2o9LO8ZZ9ohkmiUiPQP7mf4MLAe6iMiuoJ9fJiLTA6/bi8hrIrI0UGNkSIT7XROojTMvUB/m9gO0c4SIbApaZfqzQF2dT0TkmWjbM+6xRyQTrT7Az1R1oog09ffmUeABVV0Y2CE8G4i0ce7EwPfrgCUiMhuoDG4HwN+RARHpj3/LxcmqWi4ibQ6yPeMCSzAmWutVdUkUnzsH6N2YGIAiEclS1eqQz81T1Z0AIjITOBWY20Q7ZwEzVLUcoPHXg2jPuMASjIlWVdDrBvYvv5AZ9FqIbkA4dPCv8X1V6AeD7htpwDDa9owLbAzGHLTAwOtOEeklIinA6KAfvwP8pvGNiBx/gNv8WEQKRSQbf2W7j5pp9h3gssZHo6BHpGjbMy6wBGMO1S34H2kW4K/10ug3wCmBwdjPgAkHuP5D/HV6VgB/U9WVTTWmqqXAA8D7gcprUw6yPeMCm6Y2cSci1wB9VfV3bsdinGU9GGOMY6wHY4xxjPVgjDG2wmYTAAAAHUlEQVSOsQRjjHGMJRhjjGMswRhjHGMJxhjjmP8PR0zWMj9/N9gAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x22e13639c88>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 线性回归对模型匹配较好，在训练集上有1.0的得分，测试集也有99%以上的得分，说明模型与数据匹配良好，残差分布也比较符合高斯分布。散点图也和模型比较匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 score of RidgeCV on test is 0.9999909849842762\n",
      "the r2 score of RidgeCV on train is 0.999999999999999\n"
     ]
    }
   ],
   "source": [
    "#岭回归/L2正则\n",
    "from sklearn.linear_model import RidgeCV\n",
    "#设置alpha范围\n",
    "n_alphas=20\n",
    "alphas=np.logspace(-5,2,n_alphas)\n",
    "#生成岭回归模型\n",
    "ridge=RidgeCV(alphas=alphas,store_cv_values=True)\n",
    "#训练模型\n",
    "ridge.fit(x_train,y_train)\n",
    "#预测训练集\n",
    "y_test_pred_ridge=ridge.predict(x_test)\n",
    "y_train_pred_ridge=ridge.predict(x_train)\n",
    "#使用r2_score评估性能\n",
    "print('the r2 score of RidgeCV on test is',r2_score(y_test,y_test_pred_ridge))\n",
    "print('the r2 score of RidgeCV on train is',r2_score(y_train,y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAH0dJREFUeJzt3X2UHXWd5/H3px+StIEkkDQhJMEECSiPKi3i4/gExh01qL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"output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 1e-05\n"
     ]
    }
   ],
   "source": [
    "#显示\n",
    "mse_mean=np.mean(ridge.cv_values_,axis=0)\n",
    "plt.plot(np.log10(alphas),mse_mean.reshape(len(alphas),1))\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "print('alpha is:',ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.796683</td>\n",
       "      <td>0.798182</td>\n",
       "      <td>registered</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.426234</td>\n",
       "      <td>0.005118</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.353279</td>\n",
       "      <td>0.354321</td>\n",
       "      <td>casual</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.239660</td>\n",
       "      <td>0.000096</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>531</th>\n",
       "      <td>0.040750</td>\n",
       "      <td>0.005739</td>\n",
       "      <td>dteday_2012-05-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>685</th>\n",
       "      <td>0.040522</td>\n",
       "      <td>0.002086</td>\n",
       "      <td>dteday_2012-10-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>0.040058</td>\n",
       "      <td>0.001576</td>\n",
       "      <td>dteday_2011-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>653</th>\n",
       "      <td>0.039851</td>\n",
       "      <td>0.004710</td>\n",
       "      <td>dteday_2012-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>0.039739</td>\n",
       "      <td>0.005303</td>\n",
       "      <td>dteday_2011-04-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>471</th>\n",
       "      <td>0.039261</td>\n",
       "      <td>0.003674</td>\n",
       "      <td>dteday_2012-03-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>532</th>\n",
       "      <td>0.038797</td>\n",
       "      <td>0.003318</td>\n",
       "      <td>dteday_2012-05-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>470</th>\n",
       "      <td>0.038432</td>\n",
       "      <td>0.002126</td>\n",
       "      <td>dteday_2012-03-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>378</th>\n",
       "      <td>0.037494</td>\n",
       "      <td>0.001427</td>\n",
       "      <td>dteday_2011-12-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>654</th>\n",
       "      <td>0.036306</td>\n",
       "      <td>0.000516</td>\n",
       "      <td>dteday_2012-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>411</th>\n",
       "      <td>0.035830</td>\n",
       "      <td>0.000215</td>\n",
       "      <td>dteday_2012-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>0.035792</td>\n",
       "      <td>0.001022</td>\n",
       "      <td>dteday_2011-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>0.035695</td>\n",
       "      <td>-0.000225</td>\n",
       "      <td>dteday_2012-11-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>681</th>\n",
       "      <td>0.035290</td>\n",
       "      <td>0.004605</td>\n",
       "      <td>dteday_2012-10-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>622</th>\n",
       "      <td>0.035251</td>\n",
       "      <td>0.002566</td>\n",
       "      <td>dteday_2012-08-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>743</th>\n",
       "      <td>0.035156</td>\n",
       "      <td>-0.002680</td>\n",
       "      <td>dteday_2012-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>0.034174</td>\n",
       "      <td>-0.001034</td>\n",
       "      <td>dteday_2012-04-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>0.034109</td>\n",
       "      <td>0.001024</td>\n",
       "      <td>dteday_2011-06-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>0.033641</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>dteday_2012-04-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>624</th>\n",
       "      <td>0.033539</td>\n",
       "      <td>-0.001098</td>\n",
       "      <td>dteday_2012-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>714</th>\n",
       "      <td>0.033422</td>\n",
       "      <td>-0.000492</td>\n",
       "      <td>dteday_2012-11-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>377</th>\n",
       "      <td>0.032770</td>\n",
       "      <td>0.001816</td>\n",
       "      <td>dteday_2011-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>409</th>\n",
       "      <td>0.032565</td>\n",
       "      <td>-0.000492</td>\n",
       "      <td>dteday_2012-01-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>593</th>\n",
       "      <td>0.032377</td>\n",
       "      <td>0.001674</td>\n",
       "      <td>dteday_2012-07-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>410</th>\n",
       "      <td>0.032193</td>\n",
       "      <td>-0.001265</td>\n",
       "      <td>dteday_2012-01-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>0.031990</td>\n",
       "      <td>-0.000017</td>\n",
       "      <td>dteday_2012-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>-0.031634</td>\n",
       "      <td>0.001073</td>\n",
       "      <td>dteday_2012-04-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>656</th>\n",
       "      <td>-0.031667</td>\n",
       "      <td>-0.002251</td>\n",
       "      <td>dteday_2012-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>-0.031958</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>dteday_2012-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>-0.032124</td>\n",
       "      <td>-0.010877</td>\n",
       "      <td>dteday_2012-07-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>626</th>\n",
       "      <td>-0.032453</td>\n",
       "      <td>-0.004873</td>\n",
       "      <td>dteday_2012-09-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>-0.032666</td>\n",
       "      <td>0.001117</td>\n",
       "      <td>dteday_2011-09-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>594</th>\n",
       "      <td>-0.032676</td>\n",
       "      <td>0.002327</td>\n",
       "      <td>dteday_2012-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>-0.032744</td>\n",
       "      <td>0.001055</td>\n",
       "      <td>dteday_2011-12-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>-0.032921</td>\n",
       "      <td>-0.007396</td>\n",
       "      <td>dteday_2012-07-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>627</th>\n",
       "      <td>-0.032992</td>\n",
       "      <td>-0.002895</td>\n",
       "      <td>dteday_2012-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>-0.033133</td>\n",
       "      <td>-0.002709</td>\n",
       "      <td>dteday_2011-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>-0.033140</td>\n",
       "      <td>-0.002989</td>\n",
       "      <td>dteday_2012-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>412</th>\n",
       "      <td>-0.033243</td>\n",
       "      <td>-0.001289</td>\n",
       "      <td>dteday_2012-02-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>-0.033266</td>\n",
       "      <td>-0.003131</td>\n",
       "      <td>dteday_2011-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>598</th>\n",
       "      <td>-0.033463</td>\n",
       "      <td>-0.005057</td>\n",
       "      <td>dteday_2012-08-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>442</th>\n",
       "      <td>-0.033916</td>\n",
       "      <td>-0.003439</td>\n",
       "      <td>dteday_2012-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>-0.034170</td>\n",
       "      <td>-0.003261</td>\n",
       "      <td>dteday_2011-04-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>229</th>\n",
       "      <td>-0.034439</td>\n",
       "      <td>-0.001405</td>\n",
       "      <td>dteday_2011-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.034496</td>\n",
       "      <td>-0.001449</td>\n",
       "      <td>dteday_2011-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>503</th>\n",
       "      <td>-0.035486</td>\n",
       "      <td>0.001766</td>\n",
       "      <td>dteday_2012-05-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>-0.036167</td>\n",
       "      <td>-0.000918</td>\n",
       "      <td>dteday_2011-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>-0.036189</td>\n",
       "      <td>0.000030</td>\n",
       "      <td>dteday_2011-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>-0.036384</td>\n",
       "      <td>-0.000603</td>\n",
       "      <td>dteday_2011-10-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>441</th>\n",
       "      <td>-0.036603</td>\n",
       "      <td>0.000789</td>\n",
       "      <td>dteday_2012-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>-0.036933</td>\n",
       "      <td>-0.003696</td>\n",
       "      <td>dteday_2012-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>383</th>\n",
       "      <td>-0.038332</td>\n",
       "      <td>-0.004590</td>\n",
       "      <td>dteday_2012-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>-0.038944</td>\n",
       "      <td>-0.001129</td>\n",
       "      <td>dteday_2011-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>228</th>\n",
       "      <td>-0.039865</td>\n",
       "      <td>-0.003684</td>\n",
       "      <td>dteday_2011-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>381</th>\n",
       "      <td>-0.045532</td>\n",
       "      <td>-0.006669</td>\n",
       "      <td>dteday_2012-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-0.486398</td>\n",
       "      <td>-0.001172</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>747 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      coef_lr  coef_ridge            columns\n",
       "11   0.796683    0.798182         registered\n",
       "2    0.426234    0.005118                 yr\n",
       "10   0.353279    0.354321             casual\n",
       "3    0.239660    0.000096               mnth\n",
       "531  0.040750    0.005739  dteday_2012-05-30\n",
       "685  0.040522    0.002086  dteday_2012-10-31\n",
       "46   0.040058    0.001576  dteday_2011-01-31\n",
       "653  0.039851    0.004710  dteday_2012-09-29\n",
       "135  0.039739    0.005303  dteday_2011-04-30\n",
       "471  0.039261    0.003674  dteday_2012-03-31\n",
       "532  0.038797    0.003318  dteday_2012-05-31\n",
       "470  0.038432    0.002126  dteday_2012-03-30\n",
       "378  0.037494    0.001427  dteday_2011-12-29\n",
       "654  0.036306    0.000516  dteday_2012-09-30\n",
       "411  0.035830    0.000215  dteday_2012-01-31\n",
       "258  0.035792    0.001022  dteday_2011-08-31\n",
       "715  0.035695   -0.000225  dteday_2012-11-30\n",
       "681  0.035290    0.004605  dteday_2012-10-27\n",
       "622  0.035251    0.002566  dteday_2012-08-29\n",
       "743  0.035156   -0.002680  dteday_2012-12-28\n",
       "499  0.034174   -0.001034  dteday_2012-04-28\n",
       "196  0.034109    0.001024  dteday_2011-06-30\n",
       "500  0.033641    0.001392  dteday_2012-04-29\n",
       "624  0.033539   -0.001098  dteday_2012-08-31\n",
       "714  0.033422   -0.000492  dteday_2012-11-29\n",
       "377  0.032770    0.001816  dteday_2011-12-28\n",
       "409  0.032565   -0.000492  dteday_2012-01-29\n",
       "593  0.032377    0.001674  dteday_2012-07-31\n",
       "410  0.032193   -0.001265  dteday_2012-01-30\n",
       "439  0.031990   -0.000017  dteday_2012-02-28\n",
       "..        ...         ...                ...\n",
       "473 -0.031634    0.001073  dteday_2012-04-02\n",
       "656 -0.031667   -0.002251  dteday_2012-10-02\n",
       "595 -0.031958    0.000291  dteday_2012-08-02\n",
       "569 -0.032124   -0.010877  dteday_2012-07-07\n",
       "626 -0.032453   -0.004873  dteday_2012-09-02\n",
       "259 -0.032666    0.001117  dteday_2011-09-01\n",
       "594 -0.032676    0.002327  dteday_2012-08-01\n",
       "350 -0.032744    0.001055  dteday_2011-12-01\n",
       "567 -0.032921   -0.007396  dteday_2012-07-05\n",
       "627 -0.032992   -0.002895  dteday_2012-09-03\n",
       "261 -0.033133   -0.002709  dteday_2011-09-03\n",
       "565 -0.033140   -0.002989  dteday_2012-07-03\n",
       "412 -0.033243   -0.001289  dteday_2012-02-01\n",
       "198 -0.033266   -0.003131  dteday_2011-07-02\n",
       "598 -0.033463   -0.005057  dteday_2012-08-05\n",
       "442 -0.033916   -0.003439  dteday_2012-03-02\n",
       "109 -0.034170   -0.003261  dteday_2011-04-04\n",
       "229 -0.034439   -0.001405  dteday_2011-08-02\n",
       "16  -0.034496   -0.001449  dteday_2011-01-01\n",
       "503 -0.035486    0.001766  dteday_2012-05-02\n",
       "76  -0.036167   -0.000918  dteday_2011-03-02\n",
       "106 -0.036189    0.000030  dteday_2011-04-01\n",
       "289 -0.036384   -0.000603  dteday_2011-10-01\n",
       "441 -0.036603    0.000789  dteday_2012-03-01\n",
       "564 -0.036933   -0.003696  dteday_2012-07-02\n",
       "383 -0.038332   -0.004590  dteday_2012-01-03\n",
       "75  -0.038944   -0.001129  dteday_2011-03-01\n",
       "228 -0.039865   -0.003684  dteday_2011-08-01\n",
       "381 -0.045532   -0.006669  dteday_2012-01-01\n",
       "0   -0.486398   -0.001172            instant\n",
       "\n",
       "[747 rows x 3 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#计算各特征权重\n",
    "fs=pd.DataFrame({'columns':list(feat_names),'coef_lr':list((lr.coef_.T)),'coef_ridge':list((ridge.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 岭回归在模型匹配上也取得了较好的成果，训练集和测试集上都有99%以上的匹配率。alpha的取值为1e-05"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.9999986421438969\n",
      "The r2 score of LassoCV on train is 0.9999986924276985\n"
     ]
    }
   ],
   "source": [
    "#L1正则/Lasso\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "lasso=LassoCV()\n",
    "lasso.fit(x_train,y_train)\n",
    "\n",
    "y_test_pred_lasso=lasso.predict(x_test)\n",
    "y_train_pred_lasso=lasso.predict(x_train)\n",
    "\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xl0HOWZ7/Hvo9W2vFvyJu8gm8WGAIoDGBISlmtIAgkhAbLAEBIyJ5fJZCZzJ8xlDsyQ3HOSMPfeSe6QxVkOyZBhCdkcMDjsJBDANhjv8iJvki1ZsmRZi62tn/tHl0QjJKstVF3drd/nHB1XVb/d9VS31T9VvVVvmbsjIiICkBN1ASIikj4UCiIi0kuhICIiv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
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.0009426245540263145\n"
     ]
    }
   ],
   "source": [
    "mses=np.mean(lasso.mse_path_,axis=1)\n",
    "plt.plot(np.log10(lasso.alphas_),mses)\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "print('alpha is:',lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.804744</td>\n",
       "      <td>0.796683</td>\n",
       "      <td>0.798182</td>\n",
       "      <td>registered</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.426234</td>\n",
       "      <td>0.005118</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.353734</td>\n",
       "      <td>0.353279</td>\n",
       "      <td>0.354321</td>\n",
       "      <td>casual</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.239660</td>\n",
       "      <td>0.000096</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>531</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.040750</td>\n",
       "      <td>0.005739</td>\n",
       "      <td>dteday_2012-05-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>685</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.040522</td>\n",
       "      <td>0.002086</td>\n",
       "      <td>dteday_2012-10-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.040058</td>\n",
       "      <td>0.001576</td>\n",
       "      <td>dteday_2011-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>653</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.039851</td>\n",
       "      <td>0.004710</td>\n",
       "      <td>dteday_2012-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.039739</td>\n",
       "      <td>0.005303</td>\n",
       "      <td>dteday_2011-04-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>471</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.039261</td>\n",
       "      <td>0.003674</td>\n",
       "      <td>dteday_2012-03-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>532</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.038797</td>\n",
       "      <td>0.003318</td>\n",
       "      <td>dteday_2012-05-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>470</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.038432</td>\n",
       "      <td>0.002126</td>\n",
       "      <td>dteday_2012-03-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>378</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.037494</td>\n",
       "      <td>0.001427</td>\n",
       "      <td>dteday_2011-12-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>654</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.036306</td>\n",
       "      <td>0.000516</td>\n",
       "      <td>dteday_2012-09-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>411</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.035830</td>\n",
       "      <td>0.000215</td>\n",
       "      <td>dteday_2012-01-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.035792</td>\n",
       "      <td>0.001022</td>\n",
       "      <td>dteday_2011-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.035695</td>\n",
       "      <td>-0.000225</td>\n",
       "      <td>dteday_2012-11-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>681</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.035290</td>\n",
       "      <td>0.004605</td>\n",
       "      <td>dteday_2012-10-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>622</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.035251</td>\n",
       "      <td>0.002566</td>\n",
       "      <td>dteday_2012-08-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>743</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.035156</td>\n",
       "      <td>-0.002680</td>\n",
       "      <td>dteday_2012-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.034174</td>\n",
       "      <td>-0.001034</td>\n",
       "      <td>dteday_2012-04-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.034109</td>\n",
       "      <td>0.001024</td>\n",
       "      <td>dteday_2011-06-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>500</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.033641</td>\n",
       "      <td>0.001392</td>\n",
       "      <td>dteday_2012-04-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>624</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.033539</td>\n",
       "      <td>-0.001098</td>\n",
       "      <td>dteday_2012-08-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>714</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.033422</td>\n",
       "      <td>-0.000492</td>\n",
       "      <td>dteday_2012-11-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>377</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.032770</td>\n",
       "      <td>0.001816</td>\n",
       "      <td>dteday_2011-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>409</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.032565</td>\n",
       "      <td>-0.000492</td>\n",
       "      <td>dteday_2012-01-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>593</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.032377</td>\n",
       "      <td>0.001674</td>\n",
       "      <td>dteday_2012-07-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>410</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.032193</td>\n",
       "      <td>-0.001265</td>\n",
       "      <td>dteday_2012-01-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>0.031990</td>\n",
       "      <td>-0.000017</td>\n",
       "      <td>dteday_2012-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.031634</td>\n",
       "      <td>0.001073</td>\n",
       "      <td>dteday_2012-04-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>656</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.031667</td>\n",
       "      <td>-0.002251</td>\n",
       "      <td>dteday_2012-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>595</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.031958</td>\n",
       "      <td>0.000291</td>\n",
       "      <td>dteday_2012-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032124</td>\n",
       "      <td>-0.010877</td>\n",
       "      <td>dteday_2012-07-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>626</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032453</td>\n",
       "      <td>-0.004873</td>\n",
       "      <td>dteday_2012-09-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032666</td>\n",
       "      <td>0.001117</td>\n",
       "      <td>dteday_2011-09-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>594</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032676</td>\n",
       "      <td>0.002327</td>\n",
       "      <td>dteday_2012-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.032744</td>\n",
       "      <td>0.001055</td>\n",
       "      <td>dteday_2011-12-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032921</td>\n",
       "      <td>-0.007396</td>\n",
       "      <td>dteday_2012-07-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>627</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.032992</td>\n",
       "      <td>-0.002895</td>\n",
       "      <td>dteday_2012-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.033133</td>\n",
       "      <td>-0.002709</td>\n",
       "      <td>dteday_2011-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.033140</td>\n",
       "      <td>-0.002989</td>\n",
       "      <td>dteday_2012-07-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>412</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.033243</td>\n",
       "      <td>-0.001289</td>\n",
       "      <td>dteday_2012-02-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.033266</td>\n",
       "      <td>-0.003131</td>\n",
       "      <td>dteday_2011-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>598</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.033463</td>\n",
       "      <td>-0.005057</td>\n",
       "      <td>dteday_2012-08-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>442</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.033916</td>\n",
       "      <td>-0.003439</td>\n",
       "      <td>dteday_2012-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.034170</td>\n",
       "      <td>-0.003261</td>\n",
       "      <td>dteday_2011-04-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>229</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.034439</td>\n",
       "      <td>-0.001405</td>\n",
       "      <td>dteday_2011-08-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.034496</td>\n",
       "      <td>-0.001449</td>\n",
       "      <td>dteday_2011-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>503</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.035486</td>\n",
       "      <td>0.001766</td>\n",
       "      <td>dteday_2012-05-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.036167</td>\n",
       "      <td>-0.000918</td>\n",
       "      <td>dteday_2011-03-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.036189</td>\n",
       "      <td>0.000030</td>\n",
       "      <td>dteday_2011-04-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.036384</td>\n",
       "      <td>-0.000603</td>\n",
       "      <td>dteday_2011-10-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>441</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.036603</td>\n",
       "      <td>0.000789</td>\n",
       "      <td>dteday_2012-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.036933</td>\n",
       "      <td>-0.003696</td>\n",
       "      <td>dteday_2012-07-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>383</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.038332</td>\n",
       "      <td>-0.004590</td>\n",
       "      <td>dteday_2012-01-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.038944</td>\n",
       "      <td>-0.001129</td>\n",
       "      <td>dteday_2011-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>228</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.039865</td>\n",
       "      <td>-0.003684</td>\n",
       "      <td>dteday_2011-08-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>381</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.045532</td>\n",
       "      <td>-0.006669</td>\n",
       "      <td>dteday_2012-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.486398</td>\n",
       "      <td>-0.001172</td>\n",
       "      <td>instant</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>747 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     coef_lasso   coef_lr  coef_ridge            columns\n",
       "11     0.804744  0.796683    0.798182         registered\n",
       "2      0.000000  0.426234    0.005118                 yr\n",
       "10     0.353734  0.353279    0.354321             casual\n",
       "3      0.000000  0.239660    0.000096               mnth\n",
       "531    0.000000  0.040750    0.005739  dteday_2012-05-30\n",
       "685    0.000000  0.040522    0.002086  dteday_2012-10-31\n",
       "46    -0.000000  0.040058    0.001576  dteday_2011-01-31\n",
       "653    0.000000  0.039851    0.004710  dteday_2012-09-29\n",
       "135    0.000000  0.039739    0.005303  dteday_2011-04-30\n",
       "471    0.000000  0.039261    0.003674  dteday_2012-03-31\n",
       "532    0.000000  0.038797    0.003318  dteday_2012-05-31\n",
       "470    0.000000  0.038432    0.002126  dteday_2012-03-30\n",
       "378   -0.000000  0.037494    0.001427  dteday_2011-12-29\n",
       "654    0.000000  0.036306    0.000516  dteday_2012-09-30\n",
       "411   -0.000000  0.035830    0.000215  dteday_2012-01-31\n",
       "258    0.000000  0.035792    0.001022  dteday_2011-08-31\n",
       "715    0.000000  0.035695   -0.000225  dteday_2012-11-30\n",
       "681    0.000000  0.035290    0.004605  dteday_2012-10-27\n",
       "622    0.000000  0.035251    0.002566  dteday_2012-08-29\n",
       "743   -0.000000  0.035156   -0.002680  dteday_2012-12-28\n",
       "499    0.000000  0.034174   -0.001034  dteday_2012-04-28\n",
       "196    0.000000  0.034109    0.001024  dteday_2011-06-30\n",
       "500    0.000000  0.033641    0.001392  dteday_2012-04-29\n",
       "624    0.000000  0.033539   -0.001098  dteday_2012-08-31\n",
       "714   -0.000000  0.033422   -0.000492  dteday_2012-11-29\n",
       "377   -0.000000  0.032770    0.001816  dteday_2011-12-28\n",
       "409   -0.000000  0.032565   -0.000492  dteday_2012-01-29\n",
       "593    0.000000  0.032377    0.001674  dteday_2012-07-31\n",
       "410   -0.000000  0.032193   -0.001265  dteday_2012-01-30\n",
       "439   -0.000000  0.031990   -0.000017  dteday_2012-02-28\n",
       "..          ...       ...         ...                ...\n",
       "473    0.000000 -0.031634    0.001073  dteday_2012-04-02\n",
       "656   -0.000000 -0.031667   -0.002251  dteday_2012-10-02\n",
       "595    0.000000 -0.031958    0.000291  dteday_2012-08-02\n",
       "569    0.000000 -0.032124   -0.010877  dteday_2012-07-07\n",
       "626    0.000000 -0.032453   -0.004873  dteday_2012-09-02\n",
       "259    0.000000 -0.032666    0.001117  dteday_2011-09-01\n",
       "594    0.000000 -0.032676    0.002327  dteday_2012-08-01\n",
       "350   -0.000000 -0.032744    0.001055  dteday_2011-12-01\n",
       "567    0.000000 -0.032921   -0.007396  dteday_2012-07-05\n",
       "627    0.000000 -0.032992   -0.002895  dteday_2012-09-03\n",
       "261    0.000000 -0.033133   -0.002709  dteday_2011-09-03\n",
       "565    0.000000 -0.033140   -0.002989  dteday_2012-07-03\n",
       "412   -0.000000 -0.033243   -0.001289  dteday_2012-02-01\n",
       "198    0.000000 -0.033266   -0.003131  dteday_2011-07-02\n",
       "598    0.000000 -0.033463   -0.005057  dteday_2012-08-05\n",
       "442   -0.000000 -0.033916   -0.003439  dteday_2012-03-02\n",
       "109   -0.000000 -0.034170   -0.003261  dteday_2011-04-04\n",
       "229    0.000000 -0.034439   -0.001405  dteday_2011-08-02\n",
       "16    -0.000000 -0.034496   -0.001449  dteday_2011-01-01\n",
       "503    0.000000 -0.035486    0.001766  dteday_2012-05-02\n",
       "76    -0.000000 -0.036167   -0.000918  dteday_2011-03-02\n",
       "106   -0.000000 -0.036189    0.000030  dteday_2011-04-01\n",
       "289   -0.000000 -0.036384   -0.000603  dteday_2011-10-01\n",
       "441   -0.000000 -0.036603    0.000789  dteday_2012-03-01\n",
       "564    0.000000 -0.036933   -0.003696  dteday_2012-07-02\n",
       "383   -0.000000 -0.038332   -0.004590  dteday_2012-01-03\n",
       "75    -0.000000 -0.038944   -0.001129  dteday_2011-03-01\n",
       "228   -0.000000 -0.039865   -0.003684  dteday_2011-08-01\n",
       "381   -0.000000 -0.045532   -0.006669  dteday_2012-01-01\n",
       "0      0.000000 -0.486398   -0.001172            instant\n",
       "\n",
       "[747 rows x 4 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# lasso回归也取得了比较好的匹配效果，在测试集和训练集上有99%以上的匹配率。同时发现yr和month在线性回归中占有较大比重，但在岭回归和lasso回归中比重较小，lasso对register和casual的比重较大，其他因素权重基本为0，故认为并没有得到其他因数对骑车人数的影响。岭回归和线性回归权重表示比较均衡，认为有较好的匹配。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
